package configmap

import (
	"context"
	"krm_pro/config"

	"github.com/gin-gonic/gin"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var configmapSet = config.ClientSet.CoreV1().ConfigMaps

type configmapInfo struct {
	Name      string
	Namespace string
}

func MapList(r *gin.Context) {
	m := configmapInfo{}
	if err := r.ShouldBindJSON(&m); err != nil {
		r.JSON(200, gin.H{
			"status":  400,
			"message": "shouldbind fialed",
		})
		return
	}
	m.list()
}

func (c *configmapInfo) list() *corev1.ConfigMapList {
	configMap, err := configmapSet(c.Namespace).List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		panic(err.Error())
	}
	return configMap
}
